<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>附件表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <script src="../../layui/layui.js" charset="utf-8"></script>
    <script  type ="text/javascript" src="../../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src ="../../res/js/Tools.js"></script>
</head>
<body>


<table class="layui-hide" id="attachmentTab" lay-filter="atsTab"></table>






<script type="text/html" id="editTable">
    <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="checkTable">
    <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="check">审核</a>

</script>

<script type="text/html" id="lookTable">
    <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>

</script>



<script>

    //判断上传类型
    var attachType=getQueryString("attachType");
    //type=1 为查看所有数据 type=2 为审核 type=3 为查看审核完成数据
    var type=getQueryString("type");

    //表格索引
    var tableIndex;
    //表格行数据
    var tableCols;
   //表格请求路径
    var tableUrl;



    if(type==2 || type=="2"){
        console.log("审核")
        tableUrl= "../../../atsAttachmentController/selectCheckAll?attachType="+attachType
        tableCols= [[
            {type: 'checkbox', fixed: 'left'}
            ,{field:'attachName', title:'标题',fixed: 'left', width:110}
            ,{field:'attachContent', title:'内容', width:250}
            ,{field:'attachTime', title:'发布时间', width:110, sort: true}
            ,{field:'attachPublisher', title:'发布人', width:80}
            ,{field:'file1', title:'附件1', width:80, templet : '#file1'}
            ,{field:'file2', title:'附件2', width:80, templet : '#file2'}
            ,{field:'file3', title:'附件3', width:80, templet : '#file3'}
            ,{fixed: 'right', title:'操作', toolbar: '#checkTable', width:125}
        ]]
    }else if(type==3 || type=="3"){
       console.log("查看")
        tableUrl= "../../../atsAttachmentController/selectLookAll?attachType="+attachType
        tableCols= [[
            {type: 'checkbox', fixed: 'left'}
            ,{field:'attachName', title:'标题', fixed: 'left', width:120}
            ,{field:'attachContent', title:'内容', width:250}
            ,{field:'attachTime', title:'发布时间', width:110, sort: true}
            ,{field:'attachPublisher', title:'发布人', width:80}
            ,{field:'file1', title:'附件1', width:80, templet : '#file1'}
            ,{field:'file2', title:'附件2', width:80, templet : '#file2'}
            ,{field:'file3', title:'附件3', width:80, templet : '#file3'}
            ,{fixed: 'right', title:'操作', toolbar: '#lookTable', width:70}
        ]]
    }else{
        console.log("所有")
       tableUrl= "../../../atsAttachmentController/selectAll?attachType="+attachType
        tableCols= [[
            {type: 'checkbox', fixed: 'left'}
            ,{field:'attachName', title:'标题',fixed: 'left', width:120}
            ,{field:'attachContent', title:'内容', width:250}
            ,{field:'attachTime', title:'发布时间', width:110, sort: true}
            ,{field:'attachPublisher', title:'发布人', width:80}
            ,{field:'file1', title:'附件1', width:80, templet : '#file1'}
            ,{field:'file2', title:'附件2', width:80, templet : '#file2'}
            ,{field:'file3', title:'附件3', width:80, templet : '#file3'}
            ,{field:'auditState', title:'审核状态', width:110, sort: true
                ,templet : "#auditState"
            }
            ,{fixed: 'right', title:'操作', toolbar: '#editTable', width:180}
        ]]
    }

    layui.use(['table','laydate'], function(){
        var table = layui.table;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startTime',
            trigger: 'click'

        });

        laydate.render({
            elem: '#endTime',
            trigger: 'click'
        });
        tableIndex=table.render({
             elem: '#attachmentTab'
            ,url: tableUrl
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: tableCols
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(atsTab)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.open({
                            maxmin: true,
                            type : 2,
                            title : '增加页面',
                            skin : 'layui-layer-molv', // 样式类名
                            shadeClose : true,
                            shade : 0 ,
                            area : [ '100%', '100%' ],
                            //offset: '90px',// 好比margin-top
                            content : 'attachmentEdit.html?attachType='+attachType+'&id=',//iframe的url
                            end : function() {//最后才进 行
                                  //table.reload(); //刷新父页 面
                            }
                        }
                    );
                    break;
                case 'search':
                    var attachName=$("#attachName").val();
                    var attachPublisher=$("#attachPublisher").val();
                    var startTime=$("#startTime").val();
                    var endTime=$("#endTime").val();

                    tableIndex.reload({
                        url: '../../../atsAttachmentController/selectAll?attachType='+attachType,
                        where: {
                            attachName: $("#attachName").val(),
                            attachPublisher: $("#attachPublisher").val(),
                            stime:$("#startTime").val(),
                            etime:$("#endTime").val()

                        },
                        //第一页开始
                        page: {
                            curr: 1
                        }
                    });

                    $("#attachName").val(attachName);
                    $("#attachPublisher").val(attachPublisher);
                    $("#startTime").val(startTime);
                    $("#endTime").val(endTime)
                    laydate.render({
                        elem: '#startTime',
                        trigger: 'click'

                    });

                    laydate.render({
                        elem: '#endTime',
                        trigger: 'click'
                    });

                    break;
                ;


            };
        });

        //监听行工具事件
        table.on('tool(atsTab)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    url="../../../atsAttachmentController/updateIsva";
                    data$={attachId:data.attachId};
                    $.post(url,data$,function(obj){
                        if(obj===1){
                            layer.msg("删除成功");
                        }else{
                            layer.msg("删除失败");
                        }

                    },"json");
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.open({
                        maxmin: true,
                        type : 2,
                        title : '编辑',
                        shade : 0.6,
                        area : [ '100%', '100%' ],
                        content :  'attachmentEdit.html?id='+data.attachId+'&attachType='+attachType,
                        end : function() {//最后才进 行
                            // table.reload(); //刷新父页 面
                        }

                    }
                );
            } else if(obj.event == 'look'){

                layer.open({
                    maxmin: true,
                    type : 2,
                    title : '查看',
                    shade : 0.6,
                    area : [ '65%', '80%' ],
                    content : 'attachmentSee.html?attachId='+data.attachId,//iframe的url
                    end : function() {//最后才进 行
                        // table.reload(); //刷新父页 面
                    }

                })
            } else if(obj.event == "check"){
                layer.open({
                        maxmin: true,
                        type : 2,
                        title : '审核',
                        shade : 0.6,
                        area : [ '65%', '80%' ],
                        content :  'attachmentCheck.html?attachId='+data.attachId,
                        end : function() {//最后才进 行
                            // table.reload(); //刷新父页 面
                        }

                    }
                );
            }
        });
    });
    function audit(saId){
        layer.open({
            maxmin: true,
            type: 2,
            title: '审核意见',
            shade: 0.6,
            area: ['65%', '80%'],
            content: 'attachmentCheckSee.html?saId='+saId,//iframe的url
            end: function () {//最后才进 行
                // table.reload(); //刷新父页 面
            }
        })

    }
</script>
<script type="text/html" id ='file1'>
    {{# if( d.file1 != null && d.file1 != ""){ }}
    <a href="../../..{{d.file1}}" target="_blank" title="{{d.file1}}" class="layui-table-link">下载</a>
    {{# }}}
</script>
<script type="text/html" id ='file2'>
    {{# if( d.file2 != null && d.file2 != ""){ }}
    <a href="../../..{{d.file2}}" target="_blank" title="{{d.file2}}" class="layui-table-link">下载</a>
    {{# }}}
</script>
<script type="text/html" id ='file3'>
    {{# if( d.file3 != null && d.file3 != ""){ }}
    <a href="../../..{{d.file3}}" target="_blank" title="{{d.file3}}" class="layui-table-link">下载</a>
    {{# }}}
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-inline">
        <input class="layui-input" name="attachName" id="attachName"  placeholder="请输入标题"  >
    </div>
    <div class="layui-inline">
        <input class="layui-input" name="attachPublisher" id="attachPublisher"  placeholder="请输入发布人"  autocomplete="off">
    </div>
    <div class="layui-inline">
        <input class="layui-input"  id="startTime" autocomplete="off" placeholder="请选择起始的发布时间">
    </div>
    <div class="layui-inline">
        <input class="layui-input"  id="endTime" autocomplete="off" placeholder="请选择最后的发布时间">
    </div>
    <button class="layui-btn"  data-type="reload" lay-event="search">
        <!--<i class="layui-icon layui-icon-search"></i>-->
        搜索
    </button>


    {{# if(type ==1 & type=="1"){}}
    <a class="layui-btn layui-btn-normal newsAdd_btn" lay-event="add">添数据</a>
    <button class="layui-btn layui-btn-danger "  data-type="reload" lay-event="delChecked">
        删除选中
    </button>

    {{# }}}
</script>
<script type="text/html" id="auditState">
   {{# if(d.auditState==20){}}
            <a class="layui-btn layui-btn-xs layui-btn-warm" href="javascript:void(0)" title={{ d.attachId}} onclick="audit(this.title)">等待审核</a>
   {{#   }else if(d.auditState==25){}}
            <a class="layui-btn layui-btn-xs layui-btn-danger" href="javascript:void(0)" title={{ d.attachId}} onclick="audit(this.title)">未通过</a>
   {{#  }else if(d.auditState==30){}}
           <a class="layui-btn layui-btn-xs " href="javascript:void(0)" title={{ d.attachId}} onclick="audit(this.title)">通过</a>
   {{#  }}}
</script>
</body>
</html>